/*
 * This is GPL v2 licensed code. See the file LICENSE in the
 * source distribution, or www.gnu.org/copyleft/gpl.html, for
 * more information.
 *
 * Copyright (C) by Håkan Lindqvist 2006, 2007
 */


package PolicyAlgebra.Type;

import java.util.HashMap;
import java.util.TreeSet;

public class Policy {
	// This will hold the mapping between the type and the associated
	// permission set for that type.
	private HashMap<Type,PermissionSet> typePermSetHash = null;

	// This set holds the known roles in this policy.
	private TreeSet<Role> roleSet = null;

	// The following sets holds a list of known objects and their
	// corresponding type.
	private HashMap<PolicyObject,Type> objectTypeHash = null;
	private TreeSet<PolicyObject> objectSet = null;

	/** 
	 * Constructor. 
	 * 
	 * @param name The name / identifier for this policy.
	 */
	public Policy(String name) {
		objectSet = new TreeSet<PolicyObject>();
		objectTypeHash = new HashMap<PolicyObject,Type>();
		roleSet = new TreeSet<Role>();
		typePermSetHash = new HashMap<Type,PermissionSet>();
	}


	/** 
	 * Add a object spcification to the policy. 
	 * 
	 * @param object The object to add.
	 * @param type The object's type.
	 */
	public void addObject(PolicyObject object, Type type) {
		objectSet.add(object);
		objectTypeHash.put(object, type);
	}


	/** 
	 * Add a known role to this policy.
	 * 
	 * @param role The role to add.
	 */
	public void addRole(Role role) {
		roleSet.add(role);
	}


	/** 
	 * This method adds a permission set to the policy for a specific
	 * type; this method will probably only be called from a parser.
	 * 
	 * @param type The type to add the permission set for.
	 * @param permSet The permission set to be associated with a type.
	 */
	public void addPermissionSet(Type type, PermissionSet permSet) {
		typePermSetHash.put(type, permSet);
	}
}
